package com.devunion.bogdan.view.project.actions;

import com.devunion.bogdan.view.wizards.NewProjectWizard;
import com.devunion.bogdan.model.project.*;
import com.devunion.bogdan.model.project.info.ProjectInfo;
import com.devunion.bogdan.model.project.dao.ProjectDao;
import com.devunion.bogdan.util.IconHelper;
import com.devunion.bogdan.spring.Context;

import java.awt.event.ActionEvent;
import java.util.Map;
import java.util.List;

import org.apache.log4j.Logger;

import javax.swing.*;

class DeleteProjectAction extends AbstractAction {
    private static Logger log = Logger.getLogger(DeleteProjectAction.class);

    private ProjectDao projectDao;

    public DeleteProjectAction() {
        super(null, IconHelper.getIcon("DeleteProject16.gif"));
        putValue(Action.LARGE_ICON_KEY, IconHelper.getIcon("DeleteProject48.gif"));

        projectDao = (ProjectDao) Context.getContext().getBean("projectDao");
    }

    public void actionPerformed(ActionEvent e) {
        if (ProjectManager.getInstance().getCurrentProject() != null) {
            projectDao.delete(ProjectManager.getInstance().getCurrentProject());

            try {
                ProjectManager.getInstance().closeProject();
            } catch (ProjectSavingException e1) {
                log.error(e1);
            }
        }
    }
}